﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using 无线打分网站.webAPI;
using WFNetLib;

namespace 无线打分网站.Manage
{
    public partial class ExperimentManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HiddenField1.Value == null || HiddenField1.Value == "1")
            {
                HiddenField1.Value = "";
                Bind();
            }            
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string id = e.Row.Cells[0].Text;
                ((Button)e.Row.Cells[11].Controls[0]).Attributes.Add("onclick", "if(!showdialog('" + id + "')) return");
                ((Button)e.Row.Cells[12].Controls[0]).Attributes.Add("onclick", "if(!window.confirm('确定删除此课程')) return;");
                e.Row.Cells[3].Text = Server.HtmlDecode(e.Row.Cells[3].Text); 
                //e.Row.Cells[3].Attributes.Add("style", "word-break :break-all ; word-wrap:break-word");
            }
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string id = GridView1.Rows[e.RowIndex].Cells[0].Text;
            ExperimentData ed=new ExperimentData();
            ed.ID = new Guid(id);
            ExperimentDataDBOption.Delete(ed);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", " <script lanuage=javascript>alert('删除成功');</script>");
            Bind();
        }
        void Bind()
        {
            DataTable dt = ExperimentDataDBOption.DataTableSelect();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                JSON_ExperimentTime[] times = JsonSerializeHelper.DeSerialize<JSON_ExperimentTime[]>(dt.Rows[i]["Times"].ToString());
                if (times.Length != 0)
                {
                    string strTimes = "";
                    for (int j = 0; j < times.Length; j++)
                    {
                        strTimes += times[j].StartTime.ToString().Insert(2, ":") + "～" + times[j].EndTime.ToString().Insert(2, ":") + "<br/>";
                    }
                    strTimes = strTimes.Substring(0, strTimes.Length - 5);
                    dt.Rows[i]["Times"] = strTimes;
                }
            }
            GridView1.Columns[0].Visible = true;
            GridView1.DataSource = dt;
            GridView1.DataBind();
            GridView1.Columns[0].Visible = false;
        }
    }
}